/**
 *	返回数据处理json格式
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-19
 */

package com.framerock.server;

import com.framerock.baselib.Json;
import com.framerock.baselib.Rock;

import java.util.Map;

public class Response {

    public static String returnError(String msg, String code)
    {
        return "{\"code\":"+code+", \"data\":\"\", \"msg\":\""+msg+"\", \"success\":false}";
    }

    public static String returnError(String msg)
    {
        return returnError(msg, "201");
    }

    public static String returnSuccess(String data, String msg)
    {
        return "{\"code\":200, \"data\":"+data+", \"msg\":\""+msg+"\", \"success\":true}";
    }

    public static String returnSuccess(Map<String,String> amap)
    {
        return returnSuccess(Json.getJsonString(amap), "");
    }

    public static String returnSuccess(String data)
    {
        Boolean isj = Json.isJson(data);
        if(!isj)data = "\""+data+"\"";
        return returnSuccess(data, "");
    }

    public static String returnSuccess()
    {
        return returnSuccess("");
    }
}
